use std::{error::Error, fs};

use crate::args::TableListCommand;

/// Lists all cache tables.
///
/// On Linux, shared memory objects are created in a virtual filesystem, normally
/// mounted at `/dev/shm`. This function visualizes the cache tables by visiting the
/// directory.
pub fn list(command: &TableListCommand) -> Result<(), Box<dyn Error>> {
    let objects = fs::read_dir("/dev/shm")?
        .filter_map(|entry| entry.map(|e| e.path()).ok())
        .filter_map(|path| {
            path.file_name()
                .and_then(|f| f.to_str().map(|s| s.to_string()))
        });

    super::list_tables(command, objects)
}
